package org.sample.controller;

import org.sample.dao.LogDao;
import org.sample.entity.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("manage/log")
public class LogController {

    @Autowired
    private LogDao logDao;

    @RequestMapping("list")
    public String list(@RequestParam(required = false, defaultValue = "1") int pageNo,
                       @RequestParam(required = false, defaultValue = "10") int pageSize,
                       Log entity, Model model) {
        Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
        Page<Log> page = logDao.findAll(Example.of(entity), pageable);
        model.addAttribute("page", page);

        model.addAttribute("entity", entity);
        return "log/list";
    }

}